package cgb2202.recruitment01.controller;

import cgb2202.recruitment01.entity.*;
import cgb2202.recruitment01.mapper.AdminMapper;
import cgb2202.recruitment01.mapper.EmpInfoMapper;
import cgb2202.recruitment01.mapper.EmpMapper;
import cgb2202.recruitment01.mapper.IntentionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class AdminController {
    @Autowired(required = false)
    AdminMapper adminMapper;
    @Autowired(required = false)
    EmpInfoMapper empInfoMapper;
    @Autowired(required = false)
    IntentionMapper intentionMapper;

//    @RequestMapping("/admin/reg")
//    public int reg(@RequestBody Admin admin){
//        List<Admin> ad= adminMapper.selectByName(admin.getName());
//        if(ad!=null){
//            adminMapper.insert(admin);
//            return 1;
//        }else{
//            return 2;
//        }
//    }

//    /*删除求职者信息,感觉用不上*/
//    @RequestMapping("/deleteEmpInfo")
//    public void deleteEmpInfoByID(int id, HttpSession session) {
//        empInfoMapper.deleteById(id);
//    }

    /*通过求职者信息*/
    @RequestMapping("/passEmpCheck")
    public void passEmpInfoByID(int id, HttpSession session) {
        empInfoMapper.passCheckById(id);
    }

    /*驳回求职者信息*/
    @RequestMapping("/rejectEmpInfo")
    public void rejectEmpInfoByID(int id) {
        empInfoMapper.rejectCheckById(id);
    }

    /*用于给页面返回当前session中保存的用户对象*/
    @RequestMapping("/currentUser")
    CurrentUserDTO currentUser(HttpSession session) {
        CurrentUser ob = (CurrentUser)session.getAttribute("currentUser");
        CurrentUserDTO CDTO = new CurrentUserDTO(ob);
        return CDTO;
    }

    /*管理员登录*/
    @RequestMapping("/admin/login")
    int login(Admin admin) {
        Admin ad = adminMapper.selectByName(admin.getEmail());
        if (null != ad) {
            if (ad.getPassword().equals(admin.getPassword())) {
                /*登陆成功*/
                return 1;
            } else {
                /*密码错误*/
                return 2;
            }
        } else {
            /*管理员账号不存在 */
            return 3;
        }
    }

    /*管理员选择未审核的个人信息*/
    @RequestMapping("/empInfo/adminSelect")
    public List<EmpInfo> adminSelectEmpInfo() {
        List<EmpInfo> empInfos = empInfoMapper.adminSelect();
        return empInfos;
    }

    /*管理员选择未审核的就业倾向*/
    @RequestMapping("/intention/adminSelect")
    public List<Intention> adminSelectIntention() {
        List<Intention> intentions = intentionMapper.adminSelect();
        return intentions;
    }
}